package LeetCode;

/**
 * @Author: Dijah
 * @Date: 2023/7/26 19:58
 * @Desc: 转换罗马数字
 */
public class code12_intToRoman {

    public static String intToRoman(int num){
         int [] nums = {1000,900,500,400,100,90,50,40,10,9,9,4,1};
        String [] romans = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
        StringBuilder sb = new StringBuilder();
        int index = 0;
        while (index < 13){
            while (num >= nums[index]){
                sb.append(romans[index]);
                num -= nums[index];
            }
            index++;
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        String s = intToRoman(34);
        System.out.println(s);
    }
}
